package com.itxx.keycase.threadpoolexecutor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test3 {
    public static void main(String[] args) {
        //拒绝策略    new ThreadPoolExecutor.DiscardPolicy() 实际线程大于 阻塞队列中的参数+最大线程   会抛弃队列中的等待最久的任务  把当前任务加入队列中
        ThreadPoolExecutor t = new ThreadPoolExecutor(3,
                5,
                1,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),
                new ThreadPoolExecutor.DiscardPolicy());
        for (int i = 1; i <= 15; i++) {
            int y = i;
            t.submit(() -> {
                System.out.println(Thread.currentThread().getName() + "---" + y);
            });
        }
        t.shutdown();
    }
}


